home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / RecordTree.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  2.5 KB  |  76 lines

  1. package symantec.itools.db.pro;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Hashtable;
  5. import symantec.itools.db.net.NetRecord;
  6. import symjava.sql.SQLException;
  7.  
  8. class RecordTree {
  9.    NetRecord _rec;
  10.    Hashtable _detBlocks;
  11.  
  12.    RecordTree() {
  13.       this._rec = null;
  14.       this._detBlocks = null;
  15.    }
  16.  
  17.    RecordTree(NetRecord r) {
  18.       this._rec = r;
  19.       this._detBlocks = null;
  20.    }
  21.  
  22.    NetRecord getRecord() {
  23.       return this._rec;
  24.    }
  25.  
  26.    boolean isValidRec() {
  27.       return this._rec != null && this._rec.getState() != 105;
  28.    }
  29.  
  30.    synchronized void freeRecordBlocks() {
  31.       if (this.isValidRec()) {
  32.          this._rec.setState((byte)105);
  33.       }
  34.  
  35.       this._rec = null;
  36.       if (this._detBlocks != null) {
  37.          Enumeration e = this._detBlocks.elements();
  38.  
  39.          while(e.hasMoreElements()) {
  40.             RecordSet b = (RecordSet)e.nextElement();
  41.             if (b != null) {
  42.                b.freeRecordTrees();
  43.             }
  44.          }
  45.  
  46.          this._detBlocks.clear();
  47.          this._detBlocks = null;
  48.       }
  49.    }
  50.  
  51.    synchronized RecordSet getRecordSet(RelViewPos pos) throws SQLException {
  52.       RecordSet rb = this.getDetailRecordSet(pos);
  53.       if (pos.over()) {
  54.          return rb;
  55.       } else {
  56.          RecordTree rt = rb.getRecordTree(pos);
  57.          return !rt.isValidRec() ? rb : rt.getRecordSet(pos.next());
  58.       }
  59.    }
  60.  
  61.    private RecordSet getDetailRecordSet(RelViewPos pos) {
  62.       if (this._detBlocks == null) {
  63.          this._detBlocks = new Hashtable();
  64.       }
  65.  
  66.       Integer i = new Integer(pos.getID());
  67.       RecordSet rb = (RecordSet)this._detBlocks.get(i);
  68.       if (rb == null) {
  69.          rb = new RecordSet(pos.cloneAtCurrentPos());
  70.          this._detBlocks.put(i, rb);
  71.       }
  72.  
  73.       return rb;
  74.    }
  75. }
  76.